package com.text.day2_3.pk;

import java.util.Random;

public class Hero implements Fightable {
    private String name;
    private int hp;
    private int atc;

    public Hero() {
    }

    public Hero(String name, int hp, int atc) {
        this.name = name;
        this.hp = hp;
        this.atc = atc;
    }

    @Override
    public boolean isAlive() {
        if (hp <= 0)
            return false;
        else
            return true;
    }

    @Override
    public void fight(Fightable enemy) {
        Random random = new Random();
        if (random.nextInt(2) == 1){
            int atc = this.atc + random.nextInt(5) + 5;

            System.out.println(this.name + "暴击了！对" + ((Hero) enemy).getName() + "造成" + atc + "伤害");
            enemy.takeDamage(atc);
        } else {

            System.out.println(this.name + "对" + ((Hero) enemy).getName() + "造成" + this.atc + "伤害");
            enemy.takeDamage(this.atc);
        }

    }

    @Override
    public void takeDamage(int damage) {


        this.hp -= damage;
        if (this.hp > 0)
            System.out.println(this.name + "受到" + damage + "伤害，HP变为" + this.hp);
        else
            System.out.println(this.name + "OVER");
    }
    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public double getHp() {
        return hp;
    }

    public void setHp(int hp) {
        this.hp = hp;
    }

    public double getAtc() {
        return atc;
    }

    public void setAtc(int atc) {
        this.atc = atc;
    }

    @Override
    public String toString() {
        return "Hero{" +
                "name='" + name + '\'' +
                ", hp=" + hp +
                ", atc=" + atc +
                '}';
    }
}
